/*
 *  Copyright 2009 Advanced Industrial Science and Technology (AIST).
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

/*! \file
 *  \brief
 */

#include <thrust/graph/adjacency_list.hpp>
using namespace thrust;

#include <iostream>
using namespace std;

int
main( int arcg, char** argv)
{
  typedef property<vertex_color_t,int> VertexProperty;  
  typedef property<edge_weight_t,float> EdgeProperty;
  typedef adjacency_list<directedS,disallow_parallelS
    , VertexProperty
    , EdgeProperty
    > graph_t;

  typedef graph_traits<graph_t>::vertex_descriptor vertex_descriptor;
  typedef graph_traits<graph_t>::vertex_iterator   vertex_iterator;
  typedef graph_traits<graph_t>::edge_descriptor   edge_descriptor;
  typedef graph_traits<graph_t>::edge_iterator     edge_iterator;

  std::size_t N =4;
  graph_t g( N);
 
  edge_descriptor e;
  bool inserted =false;
  
  tie( e, inserted) =add_edge( 0, 1, g);
  tie( e, inserted) =add_edge( 3, 0, g);
  tie( e, inserted) =add_edge( 3, 0, g);
  tie( e, inserted) =add_edge( 1, 0, g);

  {
    property_map<graph_t,vertex_index_t>::type index =get( vertex_index, g);
    property_map<graph_t,vertex_color_t>::type color =get( vertex_color, g);
    vertex_iterator iter, last;
    tie( iter, last) =vertices( g);

    for( ; iter !=last; ++iter){
      put( vertex_color, g, *iter, 2);
    }
    
    tie( iter, last) =vertices( g);
    for( ; iter !=last; ++iter){
      cout <<*iter
	   <<": index " <<index[*iter]
	   <<", color " <<color[*iter] 
	   <<endl;
    }

    tie( iter, last) =vertices( g);
    for( ; iter !=last; ++iter){
      //color[*iter] =0;
    }

    property_map<graph_t,vertex_color_t>::type color2 =get( vertex_color, g);
    tie( iter, last) =vertices( g);
    for( ; iter !=last; ++iter){
      cout <<*iter
	   <<": index " <<index[*iter]
	   <<", color " <<color[*iter]
	   <<", color2 " <<color2[*iter]
	   <<endl;
    }

    int c =get( vertex_color, g, 0);
    std::cout <<"get: " <<c <<std::endl;
  }

  {
    float count =10.0;
    edge_iterator iter, last;
    tie( iter, last) =edges( g);
    for( ; iter !=last; ++iter){
      edge_descriptor e =*iter;
      put( edge_weight, g, e, count++);
    }
    
    property_map<graph_t,edge_weight_t>::type weight =get( edge_weight, g);  
    tie( iter, last) =edges( g);
    for( ; iter !=last; ++iter){
      edge_descriptor e =*iter;
      cout <<e <<": weight " <<weight[e] <<endl;
    }

    
  }

  return 0;
}
